wrk.method = "POST"
wrk.headers["X-Requested-With"] = "XMLHttpRequest"
wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"
wrk.headers["User-Agent"] = "Dalvik/2.1.0 (Linux; U; Android 5.1.1; MX4 Pro Build/LMY48W)"

wrk.body='{"data":{"action":"getInterfaceByVersion"},"system":{"new_version":"3.7.6","os":"APP_ANDROID","channel":999,"lo":"113.951398","la":"22.543653","city":"深圳市","ssid":"lexin","session_id":"un6o2ml2gsf4v0hc2rglcbp8v1","token_id":"Pea06B95ymRzyrLWa6kO3BAdzJTUeWuHF5XF2FUzF4kvfYtNCcvxboyN+PA3ewk5kyuydtCyXr12gByG+vN4Mw==","uid":"12615344","controller":"productInterface","machine_code":"666c872ce435f3d","time_stamp":"1488942209","scale":"2","sign":"9f1fc09954b3cfc2ad76eb18e1570e86"}}'

local tb = {}
local item = {'{"data":{"action":"getInterfaceByVersion"},"system":{"new_version":"3.7.6","os":"APP_ANDROID","channel":999,"lo":"113.951398","la":"22.543653","city":"深圳市","ssid":"lexin","session_id":"un6o2ml2gsf4v0hc2rglcbp8v1","token_id":"Pea06B95ymRzyrLWa6kO3BAdzJTUeWuHF5XF2FUzF4kvfYtNCcvxboyN+PA3ewk5kyuydtCyXr12gByG+vN4Mw==","uid":"12615344","controller":"productInterface","machine_code":"666c872ce435f3d","time_stamp":"1488942209","scale":"2","sign":"9f1fc09954b3cfc2ad76eb18e1570e86"}}', '/routev2/productInterface/getInterfaceByVersion.json'}
table.insert(tb, item)

item = {'{"data":{"action":"updateTips","platform":"fql","app_os":"android","system_code":"23"},"system":{"new_version":"3.7.6","os":"APP_ANDROID","channel":999,"lo":"113.951398","la":"22.543653","city":"深圳市","ssid":"lexin","session_id":"un6o2ml2gsf4v0hc2rglcbp8v1","token_id":"Pea06B95ymRzyrLWa6kO3BAdzJTUeWuHF5XF2FUzF4kvfYtNCcvxboyN+PA3ewk5kyuydtCyXr12gByG+vN4Mw==","uid":"12615344","controller":"other","machine_code":"666c872ce435f3d","time_stamp":"1488942209","scale":"2","sign":"041ce13ebb3f0372fee958f92f4c7030"}}', '/routev2/other/updateTips.json'}
table.insert(tb, item)

item = {'{"data":{"action":"startImg"},"system":{"new_version":"3.7.6","os":"APP_ANDROID","channel":999,"lo":"113.951398","la":"22.543653","city":"深圳市","ssid":"lexin","session_id":"un6o2ml2gsf4v0hc2rglcbp8v1","token_id":"Pea06B95ymRzyrLWa6kO3BAdzJTUeWuHF5XF2FUzF4kvfYtNCcvxboyN+PA3ewk5kyuydtCyXr12gByG+vN4Mw==","uid":"12615344","controller":"other","machine_code":"666c872ce435f3d","time_stamp":"1488942209","scale":"2","sign":"0bb01c8dae598872dacdfd61c5d27311"}}', '/routev2/other/startImg.json'}
table.insert(tb, item)

item = {'{"data":{"action":"appUserUpload","push_token":"0a023255187"},"system":{"new_version":"3.7.6","os":"APP_ANDROID","channel":999,"lo":"113.951398","la":"22.543653","city":"深圳市","ssid":"lexin","session_id":"un6o2ml2gsf4v0hc2rglcbp8v1","token_id":"Pea06B95ymRzyrLWa6kO3BAdzJTUeWuHF5XF2FUzF4kvfYtNCcvxboyN+PA3ewk5kyuydtCyXr12gByG+vN4Mw==","uid":"12615344","controller":"other","machine_code":"666c872ce435f3d","time_stamp":"1488942209","scale":"2","sign":"11543e070cbdf127783c2d5d41c79f99"}}', '/routev2/other/appUserUpload.json'}
table.insert(tb, item)

item = {}

response = function(status, headers, body)  
	responses = responses + 1
	print("body:"..body)
	if body ~= nil and string.find(body,"{\"result\":0") == nil then
		failed = failed + 1
		print("body:"..body)
	end
end 

request = function()
	requests  = requests + 1
	--local i = requests % #tb + 1
	local i = 2
	wrk.body = tb[i][1]
	path = tb[i][2]

	return wrk.format(nil, path)
end



local threads = {}
local num = 1
function setup(thread)
   thread:set("id", num)
   thread:set("failed", failed)
   table.insert(threads, thread)
   num = num + 1
end

function init(args)
   requests  = 0
   responses = 0
   failed    = 0
   local msg = "thread %d created"
   print(msg:format(id))
end


function done(summary, latency, requests)
   for index, thread in ipairs(threads) do
      local id        = thread:get("id")
      local requests  = thread:get("requests")
      local responses = thread:get("responses")
	  local failed	  = thread:get("failed")
      local msg = "thread %d made %d requests and got %d responses, %d retcode!=0"
      print(msg:format(id, requests, responses,failed))
   end
end
